package com.wsq.nutz.service;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;

import org.nutz.ioc.IocContext;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.lang.util.Context;
import org.nutz.service.IdNameEntityService;

import com.wsq.nutz.bean.User;

@IocBean
public class UserService extends IdNameEntityService<User>{

    public User add(int id , String name, String password) {
        User user = new User();
        user.setId(id);
        user.setName(name);
        user.setPassword(password);
        return user;
    }
    
    public int fetch(String name,String pwd,ServletContext context){
    	List<User> users = (List<User>) context.getAttribute("users");
    	if (users!=null && !users.isEmpty()) {
    		for(User user:users){
    			if (user.getName().equals(name)&&user.getPassword().equals(pwd)) {
    				return user.getId();
    			}
    		}
		}
    	return 0;
    }

	public void updatePassword(int me, String password) {
		
	}
	
	
}
